package com.aiyige.page.publish.service;

import com.qiniu.android.storage.UpCancellationSignal;

public abstract class MyUpCancellationSingal implements UpCancellationSignal {
    boolean forceCancel = false;
    long timestamp = 0;
    long callInterval = 500;

    public boolean isForceCancel() {
        return forceCancel;
    }

    public void setForceCancel(boolean forceCancel) {
        this.forceCancel = forceCancel;
    }

    @Override
    public boolean isCancelled() {
        if (forceCancel) {
            return true;
        }
        boolean shouldCancel = false;
        if (System.currentTimeMillis() - timestamp > callInterval) {
            timestamp = System.currentTimeMillis();
            shouldCancel = checkCancel();
        }
        return shouldCancel;
    }

    abstract boolean checkCancel();
}
